package com.rescue.controller.admin;

import com.rescue.forum.dto.CommentPageQueryDTO;
import com.rescue.result.PageResult;
import com.rescue.result.Result;
import com.rescue.service.CommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/admin/forum/comment")
@RestController
@Api(tags = "评论相关接口")
@Slf4j
public class CommentController {
    @Autowired
    private CommentService commentService;

    /**
     * 根据文章Id获取评论列表
     * @param commentPageQueryDTO
     * @return
     */
    @ApiOperation("根据文章Id获取评论列表")
    @PostMapping("/list")
    private Result<PageResult> getCommentListByArticleId(CommentPageQueryDTO commentPageQueryDTO) {
        log.info("根据文章Id获取评论列表{}",commentPageQueryDTO.getArticleId());
        PageResult pageResult = commentService.page(commentPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 根据Id删除评论
     * @param commentId
     * @return
     */
    @ApiOperation("根据Id删除评论")
    @DeleteMapping("/delete")
    private Result deleteById(Integer commentId){
        log.info("根据Id删除评论{}",commentId);
        commentService.deleteById(commentId);
        return Result.success();
    }
    @ApiOperation("审核评论")
    @PostMapping("/audit")
    private Result audit(Integer commentId){
        log.info("审核评论{}",commentId);
        commentService.audit(commentId);
        return Result.success();
    }
}
